/*
 * Copyright (C) 2014 VenomVendor <info@VenomVendor.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.naizhuai.ui.adapter.management;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.naizhuai.R;
import com.naizhuai.ui.components.CircleImageView;
import com.naizhuai.Model.db.user.PersonUserBean;
import com.naizhuai.util.ImageUtils;
import com.naizhuai.util.ListUtils;
import com.naizhuai.util.NaizhuAILog;
import com.naizhuai.util.ToastCompat;

import java.util.List;

public class AddTeamAdapterHolder extends RecyclerView.Adapter {

    public static final int LIST_TYPE_MANAGE = 0;
    public static final int LIST_TYPE_MEMBER = 1;


    private List<PersonUserBean> memberList;
    private OnItemClickListener mItemClickListener;
    private Context mContext;
    private int listType;

    public AddTeamAdapterHolder(Context context, List<PersonUserBean> memberList, int listType) {
        this.mContext = context;
        this.memberList = memberList;
        this.listType = listType;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View sView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_add_member_item, parent, false);
        return new AddTeamMemberViewHolder(sView);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof AddTeamMemberViewHolder) {
            AddTeamMemberViewHolder memberHolder = (AddTeamMemberViewHolder) holder;
            drawMemberItem(memberHolder, position);
        }
    }

    private void drawMemberItem(AddTeamMemberViewHolder memberHolder, int position) {
        memberHolder.tvMemberName.setText(memberList.get(position).getShowName());
        ImageUtils.glideThumbViewByUrl(mContext, memberHolder.cmMemberLog, memberList.get(position).getUserLogoUrl());
    }

    @Override
    public int getItemCount() {
        return memberList.size();
    }


    public class AddTeamMemberViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tvMemberName;
        CircleImageView cmMemberLog;
        ImageView memberEdit;


        public AddTeamMemberViewHolder(View view) {
            super(view);
            tvMemberName = (TextView) view.findViewById(R.id.struc_user_name);
            memberEdit = (ImageView) view.findViewById(R.id.member_edit);
            cmMemberLog = (CircleImageView) view.findViewById(R.id.struc_user_head_logo);
            memberEdit.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mItemClickListener != null) {
                mItemClickListener.onItemClick(v, getAdapterPosition(), listType);
            }
        }

    }

    public void setOnItemClickListener(OnItemClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position, int listIndex);
    }


}